registerAndLoadConfig

fun <T : Config> registerAndLoadConfig(configClass: () -> T, registerType: RegisterType = RegisterType.BOTH): T

Creates and registers a Config. Use this over registerConfig and readOrCreateAndValidate if possible.

Performs the entire creation, loading, validation, and registration process on a config class. Internally performs the two steps

  1. readOrCreateAndValidate

  2. registerConfig

Return

loaded, validated, and registered instance of T

Author

fzzyhmstrs

Since

0.2.0

Parameters

T

the config type, any subclass of Config

configClass

Function0 of config class instances

registerType

enum of RegisterType that defines which registries to register to. defaults to RegisterType.BOTH

Samples

import me.fzzyhmstrs.fzzy_config.api.ConfigApi
import me.fzzyhmstrs.fzzy_config.api.RegisterType

fun main() { 
   //sampleStart 
   //instance of your config loaded from file and automatically registered to the SyncedConfigRegistry and ClientConfigRegistry using the getId() method
var myConfig = ConfigApi.registerAndLoadConfig({ MyConfig() })

//adding the registerType, you can register a config as client-only. No syncing will occur. Useful for client-only mods.
var myClientOnlyConfig = ConfigApi.registerAndLoadConfig({ MyConfig() }, RegisterType.CLIENT)

//adding the registerType, you can register a config as sync-only. Their won't be any client-side GUI functionality, so the config will only be editable from the file itself, but it will auto-sync with clients.
var mySyncedOnlyConfig = ConfigApi.registerAndLoadConfig({ MyConfig() }, RegisterType.SERVER)

//Init function would be called in ModInitializer or some other entrypoint. Not strictly necessary if loading on-reference is ok.
fun init() {} 
   //sampleEnd
}

fun <T : Config> registerAndLoadConfig(configClass: Supplier<T>, registerType: RegisterType = RegisterType.BOTH): T

Creates and registers a Config. Use this over registerConfig and readOrCreateAndValidate if possible.

Performs the entire creation, loading, validation, and registration process on a config class. Internally performs the two steps

  1. readOrCreateAndValidate

  2. registerConfig

Return

loaded, validated, and registered instance of T

Author

fzzyhmstrs

Since

0.3.2

Parameters

T

the config type, any subclass of Config

configClass

Supplier of config class instances

registerType

enum of RegisterType that defines which registries to register to. defaults to RegisterType.BOTH

Samples

import me.fzzyhmstrs.fzzy_config.api.ConfigApi
import me.fzzyhmstrs.fzzy_config.api.RegisterType

fun main() { 
   //sampleStart 
   //instance of your config loaded from file and automatically registered to the SyncedConfigRegistry and ClientConfigRegistry using the getId() method
var myConfig = ConfigApi.registerAndLoadConfig({ MyConfig() })

//adding the registerType, you can register a config as client-only. No syncing will occur. Useful for client-only mods.
var myClientOnlyConfig = ConfigApi.registerAndLoadConfig({ MyConfig() }, RegisterType.CLIENT)

//adding the registerType, you can register a config as sync-only. Their won't be any client-side GUI functionality, so the config will only be editable from the file itself, but it will auto-sync with clients.
var mySyncedOnlyConfig = ConfigApi.registerAndLoadConfig({ MyConfig() }, RegisterType.SERVER)

//Init function would be called in ModInitializer or some other entrypoint. Not strictly necessary if loading on-reference is ok.
fun init() {} 
   //sampleEnd
}